package com.bc004346.travelus;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.bc004346.travelus.fragment.FlightsFragment;
import com.bc004346.travelus.fragment.PassengerFragment;
import com.bc004346.travelus.model.domain.Reservation;
import com.bc004346.travelus.utility.Utility;

import static com.bc004346.travelus.utility.Utility.log;
import static com.bc004346.travelus.utility.Utility.onActivityStart;
import static com.bc004346.travelus.utility.Utility.onActivityStop;

/**
 * Created by Renats on 4/4/2014.
 * PNE display and confirmation
 */
public class ConfirmationActivity extends Activity {

    @Override
    protected void onStart() {
        super.onStart();
        onActivityStart(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        onActivityStop(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_confirmation);
            TextView mPnr = (TextView) findViewById(R.id.activity_confirmation_textView_pnr);
            Button button = (Button) findViewById(R.id.activity_confirmation_button_continue);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showMyFlights();
                }
            });

            Reservation res = Utility.confirmedReservation;

            mPnr.setText(String.format(getString(R.string.activity_confirmation_textView_pnr), res.getPnr()));
            FlightsFragment flightsFragment =
                    (FlightsFragment) getFragmentManager()
                            .findFragmentById(R.id.activity_confirmation_fragment_flights);
            if (flightsFragment != null)
                flightsFragment.Populate(res.getFlights());

            PassengerFragment paxFragment =
                    (PassengerFragment) getFragmentManager()
                            .findFragmentById(R.id.activity_confirmation_fragment_passengers);
            if (paxFragment != null)
                paxFragment.Populate(res.getPassengers());
        } catch (Exception e) {
            log(e, this);
        }

    }

    private void showMyFlights() {
        Intent intent = new Intent(this, MyFlightListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
        finish();
    }
}
